/**
 * 
 */
package com.poc.hibernate.dao;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import com.poc.hibernate.factory.HibernateFactory;

/**
 * @author Charles
 *
 */
public abstract class AbstractDAO {
	protected static SessionFactory sessionFactory = null;
	private Session session;
    private Transaction tx;

    public AbstractDAO() {
        HibernateFactory.buildIfNeeded();
    }

    protected void startOperation() throws HibernateException {
        session = HibernateFactory.openSession();
        tx = session.beginTransaction();
    }

	/**
	 * @return the sessionFactory
	 */
	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * @param sessionFactory the sessionFactory to set
	 */
	public static void setSessionFactory(SessionFactory sessionFactory) {
		AbstractDAO.sessionFactory = sessionFactory;
	}

	/**
	 * @return the session
	 */
	public Session getSession() {
		return session;
	}

	/**
	 * @param session the session to set
	 */
	public void setSession(Session session) {
		this.session = session;
	}

	/**
	 * @return the tx
	 */
	public Transaction getTx() {
		return tx;
	}

	/**
	 * @param tx the tx to set
	 */
	public void setTx(Transaction tx) {
		this.tx = tx;
	}

}
